package com.nf.xiaomi.util;

import com.alibaba.druid.pool.DruidDataSourceFactory;
import com.nf.dbutils.SqlExecutor;

import javax.sql.DataSource;
import java.io.InputStream;
import java.util.Properties;

public class SqlExecutorUtils {
    private static DataSource dataSource;
    {
        try {
            Class.forName("com.mysql.jdbc.Driver");
        } catch (Exception e) {
            System.out.println("无法找到驱动类");
        }
    }

    static {
        try {
            InputStream inputStream = SqlExecutorUtils.class.getClassLoader()
                    .getResourceAsStream("db.properties");
            Properties properties=new Properties();
            properties.load(inputStream);
            dataSource= DruidDataSourceFactory.createDataSource(properties);
        } catch (Exception e) {
            throw new IllegalStateException("Create dataSource Error");
        }
    }

    public static SqlExecutor getExecutor(){
        return new SqlExecutor(dataSource);
    }
}
